Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dealing with dissapear track causing error. #475

Merged
merged 2 commits into from
Nov 26, 2024

Conversation

cropse
Copy link
Contributor

@cropse cropse commented Nov 22, 2024

In some scenarios, if a track is banned, deleted, or disappears, the playlist will contain an empty track (None). This error occurs as a result but can be easily fixed.
Error code:

  File "/config/custom_components/spotcast/__init__.py", line 360, in start_casting
    add_tracks_to_queue(client, searchResults[1:])
  File "/config/custom_components/spotcast/helpers.py", line 353, in add_tracks_to_queue
    filtered = list(filter(lambda x: x["type"] == "track", tracks))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/spotcast/helpers.py", line 353, in <lambda>
    filtered = list(filter(lambda x: x["type"] == "track", tracks))
                                     ~^^^^^^^^
TypeError: 'NoneType' object is not subscriptable

Fix empty or banned track from recommanded track
Copy link
Collaborator

@fcusson fcusson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small change just to go with the QC I'm trying to implement. Once you push the change, I'll merge for next release

custom_components/spotcast/helpers.py Outdated Show resolved Hide resolved
@fcusson
Copy link
Collaborator

fcusson commented Nov 23, 2024

@cropse would you be able to provide an example of a case where this is happening, I want to test this edge case for the current v5 build

@cropse
Copy link
Contributor Author

cropse commented Nov 26, 2024

Sure, I think it's quite hard to reproduce since it's a really rare condition.

  1. Open Discovery Weekly play list on Phone (This is probably only playlist which can be hiden so must test with this one)
  2. click miner icon to hide the song
  3. then log the tracks
  4. Found data include None in the list.
    Trimed e.g. looks like:
    {
        "collaborative": False,
        "description": "Discover &#x27;Mellow Music&#x27; 🎧 Perfect chill vibes for any time.  Updated [email protected]",
        "external_urls": {
            "spotify": "https://open.spotify.com/playlist/7ci4PEose2PtQPCOCCHKlP"
        },
        "href": "https://api.spotify.com/v1/playlists/7ci4PEose2PtQPCOCCHKlP",
        "id": "7ci4PEose2PtQPCOCCHKlP",
        "images": [
            {
                "height": None,
                "url": "https://image-cdn-ak.spotifycdn.com/image/ab67706c0000da84bcbfba1e69d1319f5dbee17f",
                "width": None,
            }
        ],
        "name": "Mellow music♭",
        "owner": {
            "display_name": "Ludwig van Beethoven",
            "external_urls": {
                "spotify": "https://open.spotify.com/user/315jlrz72kxu4bfycvwjlp6cl6k4"
            },
            "href": "https://api.spotify.com/v1/users/315jlrz72kxu4bfycvwjlp6cl6k4",
            "id": "315jlrz72kxu4bfycvwjlp6cl6k4",
            "type": "user",
            "uri": "spotify:user:315jlrz72kxu4bfycvwjlp6cl6k4",
        },
        "primary_color": None,
        "public": True,
        "snapshot_id": "AAAAfZh3P0uioQIrKFbUKri+JDEzGCxG",
        "tracks": {
            "href": "https://api.spotify.com/v1/playlists/7ci4PEose2PtQPCOCCHKlP/tracks",
            "total": 79,
        },
        "type": "playlist",
        "uri": "spotify:playlist:7ci4PEose2PtQPCOCCHKlP",
    },
    None,
    {
        "collaborative": False,
        "description": "[email protected]==The hottest pop tracks that are taking over the charts and social media. Refresh weekly so you will discover something new and exciting.!!",
        "external_urls": {
            "spotify": "https://open.spotify.com/playlist/6AZP6i1KUsgk4GtTlKdDdj"
        },
        "href": "https://api.spotify.com/v1/playlists/6AZP6i1KUsgk4GtTlKdDdj",
        "id": "6AZP6i1KUsgk4GtTlKdDdj",
        "images": [
            {
                "height": None,
                "url": "https://image-cdn-ak.spotifycdn.com/image/ab67706c0000da8448e5228e4b8f1b42e27962b5",
                "width": None,
            }
        ],
        "name": "Viral Vibes",
        "owner": {
            "display_name": "bella.7k",
            "external_urls": {
                "spotify": "https://open.spotify.com/user/314x7fx4s2zrotjoksiq65f7n2de"
            },
            "href": "https://api.spotify.com/v1/users/314x7fx4s2zrotjoksiq65f7n2de",
            "id": "314x7fx4s2zrotjoksiq65f7n2de",
            "type": "user",
            "uri": "spotify:user:314x7fx4s2zrotjoksiq65f7n2de",
        },
        "primary_color": None,
        "public": True,
        "snapshot_id": "AAAAiNu6f2goxoQdeGFThBZDlgXTX5PN",
        "tracks": {
            "href": "https://api.spotify.com/v1/playlists/6AZP6i1KUsgk4GtTlKdDdj/tracks",
            "total": 60,
        },
        "type": "playlist",
        "uri": "spotify:playlist:6AZP6i1KUsgk4GtTlKdDdj",
    },
]

I believe the song got removed should encountered similiar issue but it's hard to test IRL.

@fcusson
Copy link
Collaborator

fcusson commented Nov 26, 2024

for V5 I have a pager sytem that takes care of retrieving lists from the spotify API. I added a filter at the end to remove any NoneType object from the list doing so:

items = [x for x in items if x is not None]

That should automatically resolve the issue for any usecase

@fcusson fcusson merged commit 9ca0314 into fondberg:master Nov 26, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants